//
//  CYDisTabBarButton.m
//  CreditAddressBook
//
//  Created by LE on 15/12/15.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "CYDisTabBarButton.h"
#import "CYButtonView.h"

#define kLineHeightOrWidth 0.5f
#define kLineColor [UIColor lightGrayColor]

@interface CYDisTabBarButton ()
@end

@implementation CYDisTabBarButton

- (UIView *)topLine {
    if (!_topLine) {
        _topLine = [self lineWithWidthDirection:CYDirectionStatusTop];
    }
    return _topLine;
}

- (UIView *)leftLine {
    if (!_leftLine) {
        _leftLine = [self lineWithWidthDirection:CYDirectionStatusLeft];
    }
    return _leftLine;
}

- (UIView *)bottomLine {
    if (!_bottomLine) {
        _bottomLine = [self lineWithWidthDirection:CYDirectionStatusBottom];
    }
    return _bottomLine;
}

- (UIView *)rightLine {
    if (!_rightLine) {
        _rightLine = [self lineWithWidthDirection:CYDirectionStatusRight];
    }
    return _rightLine;
}

- (UIView *)lineWithWidthDirection:(CYDirectionStatus)status {
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = kLineColor;
    [self addSubview:line];
    switch (status) {
        case CYDirectionStatusTop:
            [line autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeBottom];
            [line autoSetDimension:ALDimensionHeight toSize:kLineHeightOrWidth];
            break;
            
        case CYDirectionStatusLeft:
            [line autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeRight];
            [line autoSetDimension:ALDimensionWidth toSize:kLineHeightOrWidth];
            break;
            
        case CYDirectionStatusBottom:
            [line autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
            [line autoSetDimension:ALDimensionHeight toSize:kLineHeightOrWidth];
            break;
            
        case CYDirectionStatusRight:
            [line autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeLeft];
            [line autoSetDimension:ALDimensionWidth toSize:kLineHeightOrWidth];
            break;
    }
    return line;
}
//- (instancetype)initWithImageName:(NSString *)imageName title:(NSString *)title description:(NSString *)description {
//    
//}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.button addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
}

- (void)btnClicked {
    if (self.block) {
        self.block();
    }
}

- (void)setFrame:(CGRect)frame {
    frame.size.height = 104;
    [super setFrame:frame];
}
@end
